<?php

class IndexModel extends Model {

	public $table = 'blog';

	public function getAllContents(){
		$Sql = "SELECT * FROM {$this->table} AS t INNER JOIN category AS c 
		ON t.cid = c.cid {$this->opt['where']} {$this->opt['order']} {$this->opt['limit']} ";
		return $this->query($Sql);
	}
	public function getCategory(){
		$Sql = "SELECT * FROM category {$this->opt['where']} ORDER BY cid ASC";
		return $this->query($Sql);
	}
	// 获得最新的
	public function getNew(){
		$data = $this->order(" bid DESC ")->limit(5)->select();
		return $data;
	}
	// 排序以点击数量列出来5条数据
	public function Click(){
		$data = $this->order(" click DESC ")->limit(5)->select();
		return $data;
	}

	public function getAllBlog($cid){
		// 统计总共几条数据
		$start = $this->field(" count(*) as c ")->where(" cid = {$cid} ")->order(" cid DESC")->select();
		// p($start);
		$page = new Page($start[0]['c'],10);
		$pageStr = $page->show_b();
		$limit = $page->limit();
		$sql ="select * from blog as b  join category as c on b.cid=c.cid where b.cid = {$cid}  order by bid desc  LIMIT {$limit} ";
		$blog = $this->query($sql);
		return array('blog'=>$blog,'page'=>$pageStr);
	}

}


    // {UY:include file ='header.html'}
?>